<?php
/**
 * Created by PhpStorm.
 * User: lx
 * Date: 2020/1/14
 * Time: 15:54
 */
namespace app\api\controller;

use app\mtadminapi\controller\AdminSysRoomManage;
use app\mtadminapi\model\MtShop;
use app\mtadminapi\model\MtShopHouse;
use app\util\ReturnCode;

class HouseData extends Base
{
    public function __construct(){
        parent::__construct();
    }
    /**
     * 房间详情查询
     * @return array|null|\PDOStatement|string|\think\Model|void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getHouseInfo(){
        $houseID = intval($this->request->get("houseID"));
        if(!$houseID){
            return $this->error(ReturnCode::EMPTY_PARAMS,"缺少参数houseID");
        }
        $obj = new MtShopHouse();
        $houseInfo = $obj->where("houseID",$houseID)->find();
        if(!$houseInfo){
            return $this->error(ReturnCode::DB_READ_ERROR,"查询失败");
        }
        $houseInfo = (new AdminSysRoomManage)->houseHandle($houseInfo);
        return $this->success("查询成功",$houseInfo);
    }

    /**
     * 店铺详情
     * @return array|null|\PDOStatement|string|\think\Model|void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getShopInfo(){
        $shopID = intval($this->request->get("shopID"));
        if(!$shopID){
            return $this->error(ReturnCode::EMPTY_PARAMS,"缺少参数shopID");
        }
        $obj = new MtShop();
        $shopInfo = $obj->where("shopID",$shopID)->find();
        if(!$shopInfo){
            return $this->error(ReturnCode::DB_READ_ERROR,"shopInfo查询失败");
        }
        $houses = (new MtShopHouse())->where("shopID",$shopID)->select();
        if($houses){
            $houses = $houses->toArray();
            foreach ($houses as $k => $v){
                $houses[$k] = (new AdminSysRoomManage)->houseHandle($v);
            }
            $shopInfo['child'] = $houses;
        }
        return $this->success("查询成功",$shopInfo);
    }
}